# coding=utf-8
import unittest,sys,HTMLTestRunner,time
sys.path.append("\TestCase")
from TestCase import *

dir="D:\\testscript\\WebAutoTest\\TestCase"

#生成测试用例集
def creatcases():
	cases=unittest.TestSuite()
	#递归获取路径下所有的测试用例
	discover=unittest.defaultTestLoader.discover(dir,pattern="test*.py",top_level_dir=None)
	for testsuite in discover:
		for testcase in testsuite:
			cases.addTests(testsuite)
	return cases	

# suite.addTest(unittest.makeSuite(login.Login))
# runner=unittest.TextTestRunner()

cases=creatcases()
#定义测试报告路径
now=time.strftime("%Y%m%d%H%M%S",time.localtime())
report="D:\\testscript\\WebAutoTest\\report\\"+now+"result.html"
rp=file(report,'wb')
#定义测试报告
runner=HTMLTestRunner.HTMLTestRunner(stream=rp,title=u'测试报告',description=u'用例执行情况：')
#执行测试用例
runner.run(cases)